/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.dao;

import br.ufc.quixada.adrs.dao.config.PostGresMapConfig;
import br.ufc.quixada.adrs.model.Descarte;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Caio
 */
public class DescarteDAO {

    public void insert(Descarte descarte) throws SQLException {
        Long id = getProxId();
        descarte.setId(id);
        PostGresMapConfig.getSqlMapClient().insert("addDescarte", descarte);
    }

    public void update(Descarte descarte) throws SQLException {
        PostGresMapConfig.getSqlMapClient().update("updateDescarte", descarte);
    }

    public void delete(Long id) throws SQLException {
        PostGresMapConfig.getSqlMapClient().delete("deleteDescarte", id);
    }

    public Descarte getById(Long id) throws SQLException {
        return (Descarte) PostGresMapConfig.getSqlMapClient().queryForObject("getDescarteById", id);
    }

    public List<Descarte> getByQuestionarioQuantitativoId(Long id) throws SQLException {
        return (List<Descarte>) PostGresMapConfig.getSqlMapClient().queryForList("getDescartesByQuestionarioQuantitativoId", id);
    }

    public List<Descarte> getByTipoAnimalId(Long id) throws SQLException {
        return (List<Descarte>) PostGresMapConfig.getSqlMapClient().queryForList("getDescartesByTipoAnimalId", id);
    }

    public Long getProxId() throws SQLException {
        Long id = (Long) PostGresMapConfig.getSqlMapClient().queryForObject("getMaxIdDescarte");
        if (id == null) {
            id = 0L;
        }
        return id + 1L;
    }
}
